package com.baichang.taoshunda.service.impl;

import com.baichang.taoshunda.dao.UserAccountDao;
import com.baichang.taoshunda.entity.UserAccount;
import com.baichang.taoshunda.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by ${wushenglu} on 2018/1/31.
 */
@Service
public class UserAccountServiceImpl implements UserAccountService {
    @Autowired
    private UserAccountDao userAccountDao;

    /**
     * 查询生活服务的账号
     *
     * @param type   分类
     * @param userId 用户编号
     * @return
     */
    @Override
    public List<Map<String, Object>> getUserAccount(Integer type, int userId) {
        return userAccountDao.getUserAccount(type, userId);
    }

    /**
     * 查看是否保存过改账号
     *
     * @param userId          用户编号
     * @param rechargeAccount 账号
     */
    @Override
    public int getUserAccountByAccount(int userId, String rechargeAccount) {

        return userAccountDao.getUserAccountByAccount(userId, rechargeAccount);
    }

    /**
     * 保存账号
     *
     * @param userId
     * @param rechargeAccount
     * @param code
     * @param type
     */
    @Override
    public void saveAccount(int userId, String rechargeAccount, Integer code, int type) {
        UserAccount userAccount = new UserAccount();
        userAccount.setCreated(new Date());
        userAccount.setAccountType(code);
        userAccount.setUserAccount(rechargeAccount);
        userAccount.setUserId(userId);
        userAccount.setType(type);
        userAccountDao.save(userAccount);
    }
}
